﻿using System;
using System.Drawing;

namespace DrawPolygonAndSquare
{
	/// <summary>
	/// 二维向量
	/// </summary>
	class Vector
	{

		private double x;

		private double y;

		public double X
		{
			get { return x; }
			set { x = value; }
		}

		public double Y
		{
			get { return y; }
			set { y = value; }
		}

		/// <summary>
		/// 无参构造器
		/// </summary>
		public Vector()
		{

		}

		/// <summary>
		/// 用两个点初始化向量
		/// </summary>
		/// <param name="start">起始点</param>
		/// <param name="end">终止点</param>
		public Vector(Point start, Point end)
		{
			X = end.X - start.X;
			Y = end.Y - start.Y;
		}

		/// <summary>
		/// 用线段初始化一个向量
		/// </summary>
		/// <param name="lineSegment">线段</param>
		public Vector(LineSegment lineSegment)
		{
			X = lineSegment.End.X - lineSegment.Start.X;
			Y = lineSegment.End.Y - lineSegment.Start.Y;
		}

		/// <summary>
		/// 获取自身长度
		/// </summary>
		/// <returns>向量长度</returns>
		public double GetLength()
		{
			return Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2));
		}

		/// <summary>
		/// 将自身和传入向量点乘
		/// </summary>
		/// <param name="vector">传入向量</param>
		/// <returns>点乘结果</returns>
		public double PointProduct(Vector vector)
		{
			return X * vector.X + Y * vector.Y;
		}

		/// <summary>
		/// 将自身和传入向量叉乘
		/// </summary>
		/// <param name="vector">传入向量</param>
		/// <returns>叉乘结果</returns>
		public double CrossProduct(Vector vector)
		{
			return X * vector.Y - vector.X * Y;
		}

	}
}